package view;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.WindowConstants;

/**
 * This code was edited or generated using CloudGarden's Jigloo
 * SWT/Swing GUI Builder, which is free for non-commercial
 * use. If Jigloo is being used commercially (ie, by a corporation,
 * company or business for any purpose whatever) then you
 * should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details.
 * Use of Jigloo implies acceptance of these licensing terms.
 * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
 * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
 * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class Help extends javax.swing.JFrame implements KeyListener {
    private static final long serialVersionUID = 1L;
    private AbstractAction okButtonAction;
    private JEditorPane textPaneHelp;
    private JButton okButton;

    public Help() {
        initGUI();
        setFocusable(true);
        addKeyListener(this);
    }

    private void initGUI() {
        try {
            setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            this.setTitle("Ludo 3k - Help");
            this.setResizable(false);
            pack();
            setSize(400, 300);
            setLocationRelativeTo(this.getParent());
            getContentPane().setLayout(null);
            getContentPane().setBackground(new java.awt.Color(255, 255, 255));
            getContentPane().add(getTextPaneHelp());
            getContentPane().add(getOkButton());

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @SuppressWarnings("serial")
    private AbstractAction getOkButtonAction() {
        if(okButtonAction == null) {
            okButtonAction = new AbstractAction("OK", null) {
                public void actionPerformed(ActionEvent evt) {
                    setVisible(false);
                }
            };
        }
        return okButtonAction;
    }

    private JEditorPane getTextPaneHelp() {
        if(textPaneHelp == null) {
            textPaneHelp = new JEditorPane();
            textPaneHelp.setText("This will read data from a file.");
            textPaneHelp.setBounds(0, 0, 382, 140);
            textPaneHelp.setEditable(false);
        }
        return textPaneHelp;
    }

    private JButton getOkButton() {
        if(okButton == null) {
            okButton = new JButton();
            okButton.setAction(getOkButtonAction());
            okButton.setText("OK");
            okButton.setBounds(320, 225, 54, 30);
        }
        return okButton;
    }

    @Override
    public void keyPressed(KeyEvent e) {
        Character c = e.getKeyChar();
        if(c.equals('\n')) {
            okButton.doClick();
        }
    }

    @Override
    public void keyReleased(KeyEvent e) {}

    @Override
    public void keyTyped(KeyEvent e) {}
}
